<?php
  require('includes/class.main.php');
  require_once('tcpdf/config/lang/eng.php'); 
  require('tcpdf/tcpdf.php');

  // get meeting object
  $manager = new MeetingManager();
  $lookup = new ScheduleLookup();
  $meetingObject = $lookup->getMeetings();

  // set vars

  // start pdf
  $pdf=new TCPDF();

  $pdf->SetCreator('TCPDF');
  $pdf->SetAuthor('Marc M.');
  $pdf->SetTitle('Alcoholics Anonymous Atlanta Meeting Schedule');
  $pdf->SetSubject('Meeting Schedule');
  $pdf->SetKeywords('Alcoholics Anonymous Atlanta Meeting Schedule'); 

  $pdf->setHeaderFont(Array('times', '', 10));
  $pdf->setHeaderMargin(5);
  $pdf->SetHeaderData("logo.jpg", 10, "Alcoholics Anonymous", "Central Office of Atlanta, Georgia"); 

  $pdf->setFooterFont(Array('times', '', 8));
  $pdf->setFooterMargin(6);

  $pdf->SetMargins(5,20,5);

  $pdf->AddPage();

  foreach($meetingObject as $city => $arr) {
    $pdf->Bookmark($city, 0, 0); 
    $pdf->SetFont('times','B', 6);
    $pdf->Cell(20,6,$city,0,1,'L');

    $pdf->SetFont('times','B', 5);
    $pdf->MultiCell(95,8,"LOCATION",1,'L',0, 0, '', '', true);
    $pdf->MultiCell(15,8,"SUNDAY",1,'L',0, 0, '', '', true);
    $pdf->MultiCell(15,8,"MONDAY",1,'L',0, 0, '', '', true);
    $pdf->MultiCell(15,8,"TUESDAY",1,'L',0, 0, '', '', true);
    $pdf->MultiCell(15,8,"WEDNESDAY",1,'L',0, 0, '', '', true);
    $pdf->MultiCell(15,8,"THURSDAY",1,'L',0, 0, '', '', true);
    $pdf->MultiCell(15,8,"FRIDAY",1,'L',0, 0, '', '', true);
    $pdf->MultiCell(15,8,"SATURDAY",1,'L',0, 1, '', '', true);

    foreach($arr as $group => $data) {
      $pdf->SetFont('times','', 5);
      $pdf->MultiCell(95,8,$group ."\n". $data['LOCATION'],1,'L',0, 0, '', '', true);

      $pdf->SetFont('times','', 5);
      $pdf->MultiCell(15,8,$data['SUNDAY'],1,'L',0, 0, '', '', true);
      $pdf->MultiCell(15,8,$data['MONDAY'],1,'L',0, 0, '', '', true);
      $pdf->MultiCell(15,8,$data['TUESDAY'],1,'L',0, 0, '', '', true);
      $pdf->MultiCell(15,8,$data['WEDNESDAY'],1,'L',0, 0, '', '', true);
      $pdf->MultiCell(15,8,$data['THURSDAY'],1,'L',0, 0, '', '', true);
      $pdf->MultiCell(15,8,$data['FRIDAY'],1,'L',0, 0, '', '', true);
      $pdf->MultiCell(15,8,$data['SATURDAY'],1,'L',0, 1, '', '', true);
      $count++;
    }
    $pdf->Ln();
  }

  // add a new page for TOC
  $pdf->AddPage();

  // write the TOC title
  $pdf->SetFont('times', 'B', 10);
  $pdf->MultiCell(0, 0, 'Table Of Contents', 0, 'C', 0, 1, '', '', true, 0);
  $pdf->Ln();

  $pdf->SetFont('times', '', 10);

  // add table of content at page 1
  $pdf->addTOC(1, 'courier', '.');

  $pdf->Output();

?>

